import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/scss/index.scss'
import lazyPlugin from 'vue3-lazy'
import loadingDirective from '@/components/base/loading/derective.js'
import noResultgDirective from '@/components/base/no-result/derective.js'
import { load, saveAll } from '@/assets/js/array-store'
import { FAVORITE_KEY, PLAY_KEY } from '@/assets/js/constant/'
import { processSongs } from '@/service/song'

// 歌曲的播放链接可能会获取,所以需要更新本地储存和vuex中的储存歌曲的播放链接url
function fetchOrUpdateAll(actionTypeList, keyList) {
  actionTypeList.forEach((actionType, index) => {
    const key = keyList[index];
    const songList = load(key);
    if (songList.length > 0) {
      processSongs(songList).then(songs => {
        store.commit(actionType, songs);
        saveAll(songs, key);
      });
    }
  });
}
fetchOrUpdateAll(['setPlayHistory', 'setFavoriteList'], [PLAY_KEY, FAVORITE_KEY])

createApp(App).use(store).use(router).use(lazyPlugin, {
  loading: require('@/assets/images/default.png')
}).directive('loading', loadingDirective).directive('no-result', noResultgDirective).mount('#app')
